package com.ssmdemo.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.ssmdemo.pojo.RoleEntity;
import com.ssmdemo.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/getRole")
public class GetRoleController {

    @Autowired
    private RoleService roleService;

    @RequestMapping("/toRoleList")
    public String toRoleList(){
        return "role/RoleList";
    }

    @RequestMapping("/toAddRole")
    public String toAddRole(){
        return "role/addRole";
    }

    @RequestMapping("/toUpdateRole/{id}")
    public String toUpdateRole(@PathVariable Integer id, Model model){
        RoleEntity roleEntity=roleService.selectById(id);
        model.addAttribute("role",roleEntity);
        return "role/updateRole";
    }

    @RequestMapping("/getRoleList")
    public String getRoleList(Model model){
        List<RoleEntity> rolelist=roleService.selectList(null);
        model.addAttribute("roleList",rolelist);
        return "role/RoleList";
    }

    @RequestMapping("/getAddRole")
    public String getAddRole(RoleEntity roleEntity){
        roleService.insert(roleEntity);
        return "redirect:getRoleList";
    }

    @RequestMapping("/getUpdateRole")
    public String getUpdateRole(RoleEntity roleEntity){
        roleService.updateById(roleEntity);
        return "redirect:getRoleList";
    }


}
